package com.jsgt.greekfire.ui.trading.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.fhx.core.base.BaseAdapter
import com.fhx.core.base.BaseViewHolder
import com.jsgt.greekfire.R
import com.jsgt.greekfire.bean.TickMarketItem
import org.jetbrains.anko.textColor

class TickMarketAdapter : BaseAdapter<TickMarketItem>() {
    var isStackFromEnd: Boolean = false
    override fun provideViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder? {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.adapter_sell_layout, parent, false)
        return VH(view)
    }

    inner class VH(itemView: View) : BaseViewHolder(itemView) {
        var tv1: TextView? = itemView.findViewById(R.id.item_sell_one)
        var tv2: TextView? = itemView.findViewById(R.id.item_sell_two)
        var tv3: TextView? = itemView.findViewById(R.id.item_sell_three)

        fun bindData(bean: TickMarketItem) {
            tv2?.text = bean.dealAmount.toString()
            tv3?.text = bean.residueNum.toString()
        }
    }

    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
        val viewHolder = holder as VH
        var pk = (position + 1)
        if (isStackFromEnd) {
            viewHolder.tv2!!.textColor =
                ContextCompat.getColor(viewHolder.tv2!!.context, R.color.trading_sell)
        } else {
            viewHolder.tv2!!.textColor =
                ContextCompat.getColor(viewHolder.tv2!!.context, R.color.trading_buy)
        }
        viewHolder.tv1!!.text = pk.toString()
        if (dataList().size > position) {
            viewHolder.bindData(dataList()[position])
        } else {
            viewHolder.tv2!!.text = "--"
            viewHolder.tv3!!.text = "--"
        }
    }

    override fun getItemCount(): Int = 5
}